
<template>
  <div class="job-page">
    <slider class="sliders" ref="slider" :pages="pages" :sliderinit="sliderinit" >
      <!-- 设置loading,可自定义 -->
      <div slot="loading">loading...</div>
    </slider>
    <jobMainInfo ref='jobMainInfo' :jobInfo ="jonDetails" :companyInfo="companyDetails"></jobMainInfo>
    <div class="purposeButton">
      <a :href="telInfo" class="fl purposeBtn" >
        <img src="/static/wechat/images/consult@2x.png">
        <span>免费咨询</span>
      </a>
      <div class="fl" @click="signUpJobs()" v-if="!signUpStatus">
        <img src="/static/wechat/images/enroll@2x.png">
        <span>免费报名</span>
      </div>
      <div class="fl" v-else>
        <img src="/static/wechat/images/enroll@2x.png">
        <span class="text-gray">已报名</span>
      </div>
    </div>
  </div>
</template>

<script>
import slider from 'vue-concise-slider'// import slider components
import jobMainInfo from './jobMainInfo'
import {gotoTop} from '../../common/utils'
import {getPosDetails,positonSignUp,getBrokers} from'@/controller'
export default {
  name: 'jobDetails',
  data () {
    return {
      msg: 'jobDetails',
      pages:[],
      jonDetails:{},
      companyDetails:{},
      sliderinit: {
        currentPage: 0,
        autoplay:4000,
        loop:true,
        infinite:1,
        slidesToScroll:1,
        timingFunction: 'ease',
        duration: 1000,
        preventDocumentMove:false
      },
      telInfo:'',
      signUpStatus:false,//已报名true，未报名false
    }
  },
  mounted(){
    let myAgentTel = localStorage.getItem('myAgentTel')
    if(!myAgentTel){
      getBrokers().then((res)=>{
        //暂时先分一个 后面再添加
        this.telInfo = 'tel:'+ res.data[0].brokerPhone
      })
    }else{
      this.telInfo = 'tel:'+ myAgentTel
    }
    gotoTop();
    this.jobId = this.$route.params.jobId;
    getPosDetails(this.jobId).then((res)=>{
      res.data.positionTag = JSON.parse(res.data.positionTag)
      this.jonDetails = res.data;
      if(this.jonDetails.signUpStatus){
        this.signUpStatus = true;
      }
      this.companyDetails = res.data.rdd_company;
      this.handleCompanyPic()
    });
  },
  components: {
    "slider":slider,
    "jobMainInfo":jobMainInfo
  },
  methods:{
    signUpJobs(){
      let bindStatus = localStorage.getItem('hasBind1');
      if(bindStatus=='true'){
        //已绑定且未报名过,报名
        //
        positonSignUp(this.jobId).then((data)=>{
          if(data.code === 0){
            localStorage.setItem('signedId'+this.jobId,true);
            this.$router.push({
              path: `/successfulRegistration`,
            });
          }else{
            this.$toast.center('报名失败');
          }
        });
      }else{
        //未绑定，先提示绑定
        let type = 1,jobId = this.jobId;
        this.$router.push({
          path: `/binding/${type}/${jobId}/`,
        });
      }
    },
    handleCompanyPic(){
      let picList = [this.companyDetails.pic1,this.companyDetails.pic2,this.companyDetails.pic3,this.companyDetails.pic4,this.companyDetails.pic5]
      for(let i = 0; i < picList.length;i++){
        if(picList[i]!==null){
          this.pages.push({
            html: '<img src="'+encodeURI(picList[i])+'">'
          })
        }
      }
    }
  }
}
</script>

<style scoped>
</style>
